# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd

if __name__ == '__main__':
    frame = pd.DataFrame({'key1': ['b', 'b', 'a', 'c', 'a', 'a', 'b'], 'data1': np.random.randint(1, 10, 7)})
    data_frame = pd.DataFrame({'key1': ['a', 'b', 'd'], 'data2': np.random.randint(1, 10, 3)})
    print frame
    print data_frame

    # 默认使用内连接， 相同的列名作为连接条件
    print pd.merge(frame, data_frame)
    print pd.merge(frame, data_frame, on='key1')
    print pd.merge(frame, data_frame, left_on='key1', right_on='key1', how='inner')
    print pd.merge(frame, data_frame, left_on='key1', right_on='key1', how='left')
    print pd.merge(frame, data_frame, left_on='key1', right_on='key1', how='right')
    print "=============更改列名================"
    rename = frame.rename(columns={'key1': 'frame_key1'})
    print rename
    print pd.merge(rename, data_frame, left_on='frame_key1', right_on='key1', how='outer')